package com.zmn.brs.utils;

import org.apache.commons.lang3.StringUtils;

import java.text.DecimalFormat;
import java.util.Arrays;

/**
 * 描述： brs业务监控系统工具类
 * @author chongw
 * @since 2021-06-08 8:41
 */
public class BrsUtil {

    //cube报表数据key y维度前缀
    public final static String DIMENSION_KEY_PRE  = "x-x-";

    //cube报表数据key
    public final static String DIMENSION_X_X_X  = "x-x-x";

    //cube报表数据title key
    public final static String DIMENSION_X_X_T  = "x-x-t";

    //家修匠公司ID
    public final static Integer JXJ_ORG_THR_ID = 40105;

    /**
     * 构造环比/同比、业务实际值的指标key
     * @param measureKey
     * @return
     */
    public static String buildKey(String measureKey) {
        return DIMENSION_KEY_PRE + measureKey;
    }

    /**
     * 构造环比/同比、业务目标对比的指标key
     * @param measureKey
     * @return
     */
    public static String buildCompareKey(String measureKey) {
        return DIMENSION_KEY_PRE + measureKey + "#1";
    }

    /**
     * 构造环比/同比增长、业务目标对比的完成率指标key
     * @param measureKey
     * @return
     */
    public static String buildCompareRatioKey(String measureKey) {
        return DIMENSION_KEY_PRE + measureKey + "#2";
    }

    /**
     * 格式化小数
     * @param d
     * @return
     */
    public static String formatDoubleToStr(double d){
        DecimalFormat format = new DecimalFormat("0.##");
        return format.format(d);
    }

    /**
     * 生成规则唯一编号
     * @param args
     * @return
     */
    public static String generateUniqueNo(Object ... args){
       String value = StringUtils.join(args, "-");
       return value;
    }

    /**
     * 字符串根据#拆分
     * @param str
     * @return
     */
    public static String[] splitStr(String str){
        return str.split("#");
    }

    /**
     * 格式化cube 数字
     * @param str
     * @return
     */
    public static Double getCubeValueFormat(String str){
        String value = str.toString().replace(",","").replace("%" , "");
        return Double.parseDouble(value);
    }

}
